import {useColorScheme} from "@/hooks/useColorScheme";
import {useFonts} from "expo-font";
import React, {useEffect} from "react";
import * as SplashScreen from "expo-splash-screen";
import {I18nextProvider} from "react-i18next";
import i18n from "@/app/i18n/i18n";
import {ThemeProvider} from "@/hooks/ThemeStyle";
import {Stack} from "expo-router";
import {ROUTES} from '@/app/route/RouteParams';
SplashScreen.preventAutoHideAsync();

function getDefaultTheme() {
    return (
        <I18nextProvider i18n={i18n}>
            <ThemeProvider>
                <Stack screenOptions={{animation:'ios',animationDuration:250}} initialRouteName={ROUTES.News}>
                    <Stack.Screen name="(tabs)" options={{headerShown: false}}/>
                    <Stack.Screen name="+not-found"/>
                    <Stack.Screen name="tableview/tableviewlist" options={{title: 'TableView', headerShown:false}}/>
                    <Stack.Screen name={ROUTES.Detail} options={{title: 'Detail', headerShown:false}}/>
                    <Stack.Screen name={ROUTES.News} options={{title: '新闻', headerShown:false}}/>
                </Stack>
            </ThemeProvider>
        </I18nextProvider>
    );
}

export function defaultApp() {
    const colorScheme = useColorScheme();
    const [loaded] = useFonts({
        SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
    });

    useEffect(() => {
        if (loaded) {
            SplashScreen.hideAsync();
        }
    }, [loaded]);

    if (!loaded) {
        return null;
    }
    return getDefaultTheme();
}
